import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardGame {
    public static final String[] suits = {"♥","♣","♦","♠"};

//    生成一副扑克牌
//    52张  4--13
    public List<Card> buyCard(){
//        定义一个一维数组，这个一维数组的每个元素是一张牌
        List<Card> cardList = new ArrayList<>();

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j <= 13; j++) {
                String suit = suits[i];
//                实例化一张牌
                Card card =new Card(suit,j);
                cardList.add(card);
            }
        }
        return cardList;
    }

//    洗牌   交换的方式进行洗牌，每一个下标的数据和其他下标的数据进行交换
    public void shuffle(List<Card> cardList){
//        生成随机下标
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    private static void swap(List<Card> cardList,int i,int j){
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

//    发牌   三个人，每人轮流抓五张牌
//    1.每个人拿到的牌放哪里
//    2.
    public List<List<Card>> getCard(List<Card> cardList){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j <3; j++) {
//               怎么接牌 每次想当于删除0下标这个牌
                Card card = cardList.remove(0);
//                放到对应人手里
                hand.get(j).add(card);
            }
        }
        return hand;
    }


}
